package request;

import java.io.OutputStream;

import response.ResponseChatGlobal;
import core.GameUser;

/**
 * Request for handling global chatting, which representing one user
 * chat with all other users in the same world.
 *
 * @author yiyi
 *
 */
public class RequestChatGlobal extends GameRequest {

    // User who requested chat (from user)
    private GameUser user;
    // User's id
    private int userId = -1;
    // Chat message.
    private String message;

    @Override
    public void parse() {
        // The message read in from the client
        message = client.readString(dataIn);
        // The user sends the message
        user = client.getUser();
        // the user id
        userId = user.getID();
    }

    /**
     * ID of user who requested this chat.
     * @return	userId
     */
    public int getUserId() {
        return userId;
    }

    /**
     * Chat message.
     * @return	message need to be sent
     */
    public String getMessage() {
        return message;
    }

    public void respond(OutputStream output) {
        // Create a chatglobal response
        ResponseChatGlobal response = new ResponseChatGlobal();
        // Set up reference
        response.set(gameServer);
        response.setUserId(userId);
        response.setUser(user);
        response.setContent(message);
        // Need to update other's queue with this response
        /* TODO implement
        gameServer.updateOthersQueue(response, gameServer.getActiveUserList(), userId);
         * 
         */
    }
}